#include <stdio.h>
#include <stdlib.h>

typedef int ElemType;
typedef struct
{
    ElemType *elem;
    int TableLen;
} SSTable;

// 顺序查找(哨兵)
int Search_Seq(SSTable ST, ElemType key)
{
    ST.elem[0] = key;
    int i;
    for (i = ST.TableLen; ST.elem[i] != key; i--)
        ;     // 从后往前找
    return i; // 查找成功,返回元素下标,失败,返回0
}

int main()
{
    ElemType data[] = {1, 2, 3, 4, 5, 6};
    int len = sizeof(data) / sizeof(ElemType);
    SSTable ST = {data, len};
    ElemType key = 5;
    int index = Search_Seq(ST, key);
    if (index != 0)
    {
        printf("元素:%d 在位置 %d\n", key, index);
    }
    else
    {
        printf("查找失败!\n");
    }
    return 0;
}